package com.example.common.handler;

import com.example.common.commonsutils.R;
import com.example.common.exception.GuliException;
import com.example.common.exception.sub.TeacherNotFoundException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author:tjf
 * @Description:
 */
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public R exceptionHandler(Exception e){
        log.error(e.getMessage());
        e.printStackTrace();
        return R.error().message("系统忙，请稍后重试");
    }
    @ExceptionHandler(ArithmeticException.class)
    @ResponseBody
    public R error(ArithmeticException e){
        log.error(e.getMessage());
        e.printStackTrace();
        return R.error().message("ArithmeticException");
    }
    @ExceptionHandler(TeacherNotFoundException.class)
    @ResponseBody
    public R notFound(TeacherNotFoundException te){
        log.error(te.getMsg());
        te.printStackTrace();
        return R.error().message(te.getMsg());
    }
    @ExceptionHandler(GuliException.class)
    @ResponseBody
    public R guliException(GuliException ge){
        log.error(ge.getMsg());
        ge.printStackTrace();
        return R.error().message(ge.getMsg());
    }
}
